using System;
using System.Collections.Generic;
using Gtk;

namespace JiveMessengerLinux
{
	public static class Extension
	{
		public static List<int> AllIndexesOf(this string str, string value)
		{
			if (String.IsNullOrEmpty(value))
				throw new ArgumentException("the string to find may not be empty", "value");
			List<int> indexes = new List<int>();
			for (int index = 0; ; index += value.Length)
			{
				index = str.IndexOf(value, index, StringComparison.Ordinal);
				if (index == -1)
					return indexes;
				indexes.Add(index);
			}
		}
		public static string TrimEnd(this string source, string value)
		{
			return !source.EndsWith(value) ? source : source.Remove(source.LastIndexOf(value, StringComparison.Ordinal));
		}
		
		public static void AddRange<TK, TS>(this Dictionary<TK, TS> source, Dictionary<TK, TS> collection)
		{
			if (collection == null)
			{
				throw new ArgumentNullException("collection");
			}
			
			foreach (var item in collection)
			{
				if (!source.ContainsKey(item.Key))
				{
					source.Add(item.Key, item.Value);
				}
			}
		}
	}

    public static class WindowExtensions
    {
                    public static void Nudge(this Window window)
                {

                System.Timers.Timer dt = new System.Timers.Timer();
        
        
                    int counter = 0;
                    int shake = 0;
                    int originalX;
                    int originalY;
            window.GetPosition(out originalX,out originalY);
                    dt.Elapsed += delegate
                    {
                        counter++;
                    int x;
                    int y;
                window.GetPosition(out x,out y);
                        switch (shake)
                        {
        
                            case 0:
                        window.Move(x+5,y+10);
                        window.ShowAll();
                                shake = 1;
                                break;
                            case 1:
                        window.Move(x-5,y-10);
                        window.ShowAll();
                                shake = 0;
                                break;
                        }
        
                        if (counter == 40)
                        {
                            dt.Stop();
                    window.Move(originalX,originalY);
                        }
                    };
                    dt.Interval = 25;
                    dt.Start();
                }
    }
}

